package com.ctshk.rpc.season.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.enums.IsDeletedCode;
import com.ctshk.rpc.season.entity.SeasonProductStrategyNotes;
import com.ctshk.rpc.season.mapper.SeasonProductStrategyNotesMapper;
import com.ctshk.rpc.season.service.ISeasonProductStrategyNotesService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;


/**
 * <p>
 * 套票加幅策略备注 服务实现类
 * </p>
 *
 * @author 杨林
 * @since 2021-03-16
 */
@DubboService
public class SeasonProductStrategyNotesServiceImpl extends ServiceImpl<SeasonProductStrategyNotesMapper, SeasonProductStrategyNotes> implements ISeasonProductStrategyNotesService {

    @Autowired
    private SeasonProductStrategyNotesMapper notesMapper;


    /* @MethodName: 保存或者修改 固定套票 策略补充信息
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/3/16 14:25
     **/
    @Override
    public void saveOrUpdateSeasonProductNotes(Long seasonProductId, String storeNotes, String deptNotes, String supplierNotes, Long userId) {
        SeasonProductStrategyNotes notes = notesMapper.selectOne(new QueryWrapper<SeasonProductStrategyNotes>().lambda().eq(SeasonProductStrategyNotes::getSeasonProductId, seasonProductId));
        boolean flag = false;
        LocalDateTime now = LocalDateTime.now();
        if (notes != null) {
            flag = true;
            notes.setModifiedId(userId);
            notes.setGmtModified(now);
        } else {
            notes = new SeasonProductStrategyNotes();
            notes.setSeasonProductId(seasonProductId);
            notes.setCreateId(userId);
            notes.setGmtCreate(now);
            notes.setIsDeleted(IsDeletedCode.NO.getCode());
        }
        notes.setStoreNotes(storeNotes);
        notes.setDeptNotes(deptNotes);
        notes.setSupplierNotes(supplierNotes);
        if (flag) {//表示修改
            notesMapper.updateById(notes);
        } else {
            notesMapper.insert(notes);
        }

    }
}
